package com.wswy.wzcx.jpush;


import android.content.Context;
import android.os.Bundle;
import com.wswy.wzcx.jpush.IPushOperator.OnPushOperatorCallback;
import java.util.Set;

/**
 * 推送消息处理
 */
public class NotificationHandler {

  private IPushOperator mPushOperator;

  private Context mContext;

  private Bundle mCurrBundle;

  NotificationHandler(Context context,int pushType,boolean debug) {
    mContext = context;
    IPushOperator operator = null;
    switch (pushType){
      case PushChannel.TYPE_JPUSH:
        operator = new UmengPushImpl();
        break;
        default:
          throw new RuntimeException("unsupport push type!");
    }
    try {
      operator.initPush(context,debug);
    } catch (Throwable e) {
      e.printStackTrace();
    }
    this.mPushOperator = operator;
  }

  /**
   * 设置推送别名，覆盖之前的别名
   * @param alias
   */
  public void setAlias(String alias,OnPushOperatorCallback<String> callback){
    mPushOperator.setAlias(mContext,alias,callback);
  }

  public void setMobileNumber(String mobileNumber,OnPushOperatorCallback<String> callback){
    mPushOperator.setMobileNumber(mContext,mobileNumber,callback);
  }

  /**
   * 删除推送别名
   */
  public void deleteAlias(OnPushOperatorCallback<String> callback){
    mPushOperator.deleteAlias(mContext,null,callback);
  }

  /**
   * 设置tag标签，累加之前的标签
   * @param tags
   */
  public void setTags(Set<String> tags,OnPushOperatorCallback<Set<String>> callback){
    mPushOperator.setTags(mContext,tags,callback);
  }

  public void addTag(String tag,OnPushOperatorCallback<Set<String>> callback){
    mPushOperator.addTag(mContext,tag,callback);
  }

  public void deleteTags(Set<String> tags,OnPushOperatorCallback<Set<String>> callback){
    mPushOperator.deleteTags(mContext,tags,callback);
  }

  public void getTags(OnPushOperatorCallback<Set<String>> callback){
    mPushOperator.getTags(mContext,callback);
  }

  public void cleanTags(OnPushOperatorCallback<Boolean> callback){
    mPushOperator.cleanTags(mContext,callback);
  }

  /**
   * 记录当前点击的推送数据
   * @param bundle
   */
  public synchronized void saveCurrentPush(Bundle bundle){
    mCurrBundle = new Bundle(bundle);
  }

  /**
   * 获取当前点击的推送数据，只可以调用一次
   * @return
   */
  public synchronized Bundle getCurrentClickPush(){
    final Bundle bundle = mCurrBundle;
    mCurrBundle = null;
    return bundle;
  }



  public void switchPush(boolean status){
    mPushOperator.switchPush(mContext,status);
  }


  public void stopPush() {
    mPushOperator.stopPush(mContext);
  }

  public void resumePush() {
    mPushOperator.resumePush(mContext);
  }
}
